package com.tul.exercise.base.clazz.base.eg5;

import com.tul.exercise.base.clazz.clazzmethod.FancyToy;
import com.tul.exercise.base.clazz.clazzmethod.Toy;

import static com.tul.exercise.base.utils.Print.print;

/**
 * @author tul
 * 《java编程思想》 14章 示例5:泛化父类的实例化
 *
 */
public class GenericToyTest {

    public static void main(String[] args) {
        // 子类类型
        Class<FancyToy> ftClass = FancyToy.class;

        try {
            FancyToy fancyToy = ftClass.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            print("实例化异常,class=" + ftClass.getSimpleName());
        }

        // 泛型的父类类型
        Class< ? super FancyToy> up = ftClass.getSuperclass();
        // 编译不过
        // Class<Toy> up2 = ftClass.getSuperclass();

        try {
            Object obj = up.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            print("实例化异常,class=" + up.getSimpleName());
        }



    }

}






